﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 输入管理器, 配合事件监听来进行
/// </summary>
public class InputManager : Singleton<InputManager>
{
    private EventManager eventManager;
    private bool isStartCheck = true;

    public InputManager()
    {
        eventManager = EventManager.Instance;
        MonoEvent.Instance.UPDATE += Tick;
    }

    /// <summary>
    /// 控制检测与否的阀门
    /// </summary>
    public void StartOrEndCheck(bool _isStartCheck)
    {
        isStartCheck = _isStartCheck;
    }

    void Tick()
    {
        if (!isStartCheck)
            return;
        CheckInputKey(KeyCode.W);
        CheckInputKey(KeyCode.S);
        CheckInputKey(KeyCode.A);
        CheckInputKey(KeyCode.D);
        CheckMouseKey(0);
        CheckMouseKey(1);
        CheckMouseKey(2);
    }

    void CheckInputKey(KeyCode keyCode)
    {
        if (Input.GetKeyDown(keyCode))
        {
            eventManager.EventTrigger("KeyDown", keyCode);
        }

        if (Input.GetKeyUp(keyCode))
        {
            eventManager.EventTrigger("KeyUp", keyCode);
        }
    }

    void CheckMouseKey(int mouseKey)
    {
        if (Input.GetMouseButtonDown(mouseKey))
            eventManager.EventTrigger("MouseDown", mouseKey);
        if (Input.GetMouseButtonUp(mouseKey))
            eventManager.EventTrigger("MouseUp", mouseKey);
    }
}
